package com.wn.web;

import com.github.pagehelper.PageInfo;
import com.wn.common.pojo.PageParam;
import com.wn.common.pojo.Rsp;
import com.wn.common.pojo.TravelAngency;
import com.wn.service.TravelAngncyService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;



@RestControllerAdvice
@RequestMapping("travelAngncy")
@Api(value = "旅行社信息控制",description = "旅行社信息控制")
public class TravelAngncyController {
    @Autowired
    private TravelAngncyService travelAngncyService;

    /**
     * 查询所有入驻的旅行社
     * @param
     * @param
     * @return
     */
    @PostMapping("queryAll")
    public Rsp queryAll(@RequestBody PageParam<TravelAngency> travelAngencyPageParam){
        PageInfo<TravelAngency> travelAngencyPageInfo = travelAngncyService.queryAll(travelAngencyPageParam);
        return new Rsp().success(travelAngencyPageInfo);
    }

    /**
     * 添加旅行社数据
     * @param travelAngency
     * @return
     */
    @PostMapping("addTravelAngency")
    public Rsp addTravel(@RequestBody @Valid TravelAngency travelAngency){
        Rsp addtravel = travelAngncyService.addtravel(travelAngency);
        return addtravel;
    }

    /**
     * 通过旅行社id获得对应的旅行社
     * @param travelId
     * @return
     */
    @GetMapping("getTravelById")
    public Rsp getTravelById(Integer travelId){
        Rsp travelById = travelAngncyService.getTravelById(travelId);
        return travelById;
    }

    /**
     * 通过主键删除
     * @param
     * @return
     */
    @PostMapping("deleteByPrimaryKey")
    public Rsp deleteByPrimaryKey(@RequestBody TravelAngency travelAngency){
        Rsp primaryKey = travelAngncyService.deleteByPrimaryKey(travelAngency);
        return primaryKey;
    }

    /**
     * 通过主键更新
     * @param travelAngency
     * @param updateUserId
     * @return
     */
    @PostMapping("updateByPrimaryKey")
    public Rsp updateByPrimaryKey(@RequestBody @Valid TravelAngency travelAngency,Integer updateUserId){
        Rsp rsp = travelAngncyService.updateByPrimaryKey(travelAngency,updateUserId);
        return rsp;
    }

    @PostMapping("updateNewsinfo")
    public Rsp updateNewsinfo(@RequestBody TravelAngency travelAngency){
        Rsp rsp = travelAngncyService.updateNewsinfo(travelAngency);
        return rsp;
    }

}
